<?php
class GoodsFormModel extends Model{
	
	public $table = 'goods_type';
	private $cid;
	public function __init(){
		$this->cid = Q('cid',0,'intval');
	}
	
	public function get(){
		$map['gtid'] = M('category')->where('cid = '.$this->cid)->getField('gtid');
		$attrData = M('goods_attr')->where($map)->all();
		foreach($attrData as $n=>$attr){
			$map['attr_aid'] = $attr['aid'];
			$attrValue = M('goods_attr_value')->where($map)->all();
			$fun = $attr['show_type'];
			$attrData[$n]['html'] = $this->$fun($attr,$attrValue);
		}
		return $attrData;
	}
	/**
	 * 组合单选按钮表单
	 */
	public function radio($attr,$attrValue){
		$str = '<tr>';
		$str.="<th>{$attr['attr_name']}</th><td>";
		foreach ($attrValue as $key => $value) {
			$str.="<label><input type='radio' name='' />&nbsp;&nbsp;{$value['av_value']}</label>  &nbsp; &nbsp; &nbsp;";
		}
		$str.='</td></tr>';
		return $str;
	}
	/**
	 * 组合多选按钮表单
	 */
	public function checkbox($attr,$attrValue){
		$str = '<tr>';
		$str.="<th>{$attr['attr_name']}</th><td>";
		foreach ($attrValue as $key => $value) {
			$str.="<label><input type='checkbox' name='' />&nbsp;{$value['av_value']}</label>&nbsp;";
		}
		$str.='</td></tr>';
		return $str;
	}
	/**
	 * 组合文本表单
	 */
	public function text($attr,$attrValue){
		$str.="<tr><th>{$attr['attr_name']}</th><td>";
		return $str.="<td><input type='text' name='' value='{$attrValue['av_value']}' /></td></tr>";
	}
	/**
	 * 组合下拉列表表单
	 */
	public function select($attr,$attrValue){
		$str.="<tr><th>{$attr['attr_name']}</th><td><select name=''>";
		foreach ($attrValue as $key => $value) {
			$str.="<option value=''>{$value['av_value']}</option>";
		}
		$str.='</select></td></tr>';
		return $str;
	}
	
}
